package com.enums;

/**
 * @author ANG.YU
 * @date 2020-08-05 16:30
 */

enum Shrubbery{GROUND,CRAWLING,HANGING}

public class EnumClass {
    public static void main(String[] args) {
        for (Shrubbery s : Shrubbery.values()) {
            System.out.println(s + "ordinal" + s.ordinal());//返回一个int值，enum实例在声明时的次序，从0开始
            System.out.print(s.compareTo(Shrubbery.CRAWLING)+" ");
            System.out.print(s.equals(Shrubbery.CRAWLING)+" ");
            System.out.println(s==Shrubbery.CRAWLING);
            System.out.println(s.getDeclaringClass());//获取其所属的类
            System.out.println(s.name());//返回enum实例的名字，与toString一致
            System.out.println("**************************");
        }
        for (String s : "HANGING CRAWLING GROUND".split(" ")) {
            Shrubbery shrub = Enum.valueOf(Shrubbery.class, s);//静态方法，根据name返回对应的实例，若不存在则抛出异常
            System.out.println(shrub);
        }
    }
}
